package com.genITeam.ria.dao;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.hibernate.Session;
import org.hibernate.criterion.Order;

import com.genITeam.ria.exception.NGFException;
import com.genITeam.ria.vo.Events;
import com.genITeam.ria.vo.ResponseVo;

public class EventDAO {

	public EventDAO(){		
		BasicConfigurator.configure();		
	}
	
	Logger logger = Logger.getLogger(EventDAO.class);
	
	/**
	 * getEventDetail return the Events Detail Object
	 * 
	 * @param Session
	 * 
	 * @return ResponseVo
	 * @throws NGFException
	 */	
	
	public ResponseVo getEventDetail(Session session) throws NGFException{		

		ResponseVo responseVo = new ResponseVo();
		List eventList = null;	
		ArrayList eventArrayList  = eventArrayList= new ArrayList();
		try {
			logger.info("Start getEventDetail");	
			eventList = session.createCriteria(Events.class).addOrder(Order.desc("eventDate")).list();
			
			eventArrayList.addAll(eventList);
			responseVo.setEventList(eventArrayList);
			
			
		} catch (Exception e) {
			System.out.println(e.toString());
			logger.error(e.toString());
			throw new NGFException(e.getMessage());
		}
		
		return responseVo;
	}
	
	
	/**
	 * saveEvent return the Events Detail Object
	 * 
	 * @param Events, Session
	 * 
	 * @return none
	 * @throws NGFException
	 */	
		
	public void saveEvent(Events events, Session session) throws NGFException{
		
		try {
			logger.info("Start saveEvent");	
			session.saveOrUpdate(events);
		    
		} catch(Exception e){
			logger.error("Exception = " + e.toString());
			throw new NGFException (e.getMessage());			
		}
	}
	
	
	/**
	 * deleteEvent Used to delete the event
	 * 
	 * @param Events, Session
	 * 
	 * @return none
	 * @throws NGFException
	 */	
			
	public void deleteEvent(Events events, Session session) throws NGFException{
		
		try {
			logger.info("Start deleteEvent");	
			session.delete(events);
		    
		} catch(Exception e){
			logger.error("Exception = " + e.toString());
			throw new NGFException (e.getMessage());			
		}
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
